package com.teamsun.mqtt.entity.vo;

import java.util.Calendar;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

import com.teamsun.mqtt.entity.SendMsg;

/**
 * 
 * @author acer
 *
 */
public class DelayWillRemoveMsg extends SendMsg implements  Delayed{

	long  willRemoveTime;
	
	SendMsg sendMsg;
	
	
	public  DelayWillRemoveMsg(SendMsg sendMsg) {
		this.sendMsg=sendMsg;
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.HOUR,3);
		willRemoveTime=calendar.getTimeInMillis();
	}
	
	public DelayWillRemoveMsg(long willRemoveTime){
		this.willRemoveTime=willRemoveTime;
		
	}
	

	
	@Override
	public int compareTo(Delayed o) {

		if(o instanceof  DelayWillRemoveMsg){
			DelayWillRemoveMsg removeMsg=(DelayWillRemoveMsg)o;
			return (int)(this.willRemoveTime-removeMsg.willRemoveTime);
		}
		return 1;

	}

	@Override
	public long getDelay(TimeUnit unit) {
		return 	unit.convert(
				willRemoveTime-( Calendar.getInstance().getTimeInMillis()),
				TimeUnit.MILLISECONDS);
	}

	public SendMsg getSendMsg() {
		return sendMsg;
	}

	public void setSendMsg(SendMsg sendMsg) {
		this.sendMsg = sendMsg;
	}

	
}
